﻿<%
Class SeoClass

	Public BaiDuSearchLeftStr, SearchSiteLeftStr, SearchTopLeftStr, SearchTopRnStr, SearchTopQ1Str
	
	Public SeoClassInfo_Ori_Url, zTnT_Pr_URL, zTnT_Baidu_UpdateDate_Url, zTnT_Baidu_Pages_URL
	
	Public SeoClassInfo_Pr, SeoClassInfo_Baidu_UpdateDate, SeoClassInfo_Baidu_Pages

	Public Baidu_Keyword_Str, Baidu_Keyword_Urls, Baidu_Key_Url, Baidu_Keyword_PageS, Baidu_Mode

	Public zGolbal_Seo_JJ, zGolbal_Seo_Price
	
	Private HttpObj

	Private Sub Class_Initialize()
		BaiDuSearchLeftStr = "http://www.baidu.com/s?wd="
		SearchSiteLeftStr = "site:"
		SearchTopLeftStr = "http://www.baidu.com/s?"
		SearchTopRnStr = "rn"
		SearchTopQ1Str = "q1"
		zGolbal_Seo_JJ = 8
		zGolbal_Seo_Price = 16
		Set HttpObj = New Chen_Http
	End Sub

	Private Sub Class_Terminate()
		Set HttpObj = Nothing
	End Sub
	
	Public Function zTiChuOther(zOldTDayformat)
		zTiChuOther = zOldTDayformat
		If InStr(CStr(zTiChuOther),"小时")>0 Or InStr(CStr(zTiChuOther),"天")>0 Then
			zTiChuOther = CDate(Year(Now()) & "-" & Month(Now()) & "-" & Day(Now()))
		End If
	End Function

	Private Function zGetWWW_PRUrl(zGetWWW_PRUrl_Ori)
		Set DelphiASPObj = Server.CreateObject("Dll_PRCheckNum.TPr_Dll")
		Session("zDelphiUrl") = zGetWWW_PRUrl_Ori
		DelphiASPObj.zUrlToNum
		zGetWWW_PRUrl = Session("zDelphiCh")
		Set DelphiASPObj = Nothing
	End Function
	
	Private Sub zGetWWW_PRUrl_redir(url)
		Response.Redirect(zGetWWW_PRUrl(url))
	End Sub
	
	Private Function zGetWWW_PRUrl_Txt2Pr(zGetWWW_PRUrl_Txt2Pr_Text)
		zGetWWW_PRUrl_Txt2Pr = 0
		If zGetWWW_PRUrl_Txt2Pr_Text<>"" And Len(zGetWWW_PRUrl_Txt2Pr_Text)<20 Then
			zGetWWW_PRUrl_Txt2Pr = Replace(zGetWWW_PRUrl_Txt2Pr_Text,"Rank_1:1:","")
		End If
	End Function

	Public Function zGetWWW_BaiduUpdate(zGetWWW_BaiduUpdate_Ori)
		zGetWWW_BaiduUpdate = BaiDuSearchLeftStr & zGetWWW_BaiduUpdate_Ori
	End Function

	Public Function zGetWWW_BaiduUpdate_Txt2Date(zGetWWW_BaiduUpdate_Txt2Date_Text)
		zGetWWW_BaiduUpdate_Txt2Date = ""
		zTmp1 = "<span class=""g"">  <b>"
		If InStr(zGetWWW_BaiduUpdate_Txt2Date_Text,zTmp1) > 0 Then
			zGetWWW_BaiduUpdate_Txt2Date_Text = Mid(zGetWWW_BaiduUpdate_Txt2Date_Text, InStr(zGetWWW_BaiduUpdate_Txt2Date_Text,zTmp1)+Len(zTmp1), Len(zGetWWW_BaiduUpdate_Txt2Date_Text) )
			If InStr(zGetWWW_BaiduUpdate_Txt2Date_Text,"</span>") > 0 Then
				zGetWWW_BaiduUpdate_Txt2Date_Text = Mid(zGetWWW_BaiduUpdate_Txt2Date_Text, 1, InStr(zGetWWW_BaiduUpdate_Txt2Date_Text,"</span>")-1 )
				If InStr(zGetWWW_BaiduUpdate_Txt2Date_Text,"</b>/") > 0 Then
					zGetWWW_BaiduUpdate_Txt2Date_Text = Mid(zGetWWW_BaiduUpdate_Txt2Date_Text, InStr(zGetWWW_BaiduUpdate_Txt2Date_Text,"</b>/")+5, Len(zGetWWW_BaiduUpdate_Txt2Date_Text) )
					If zGetWWW_BaiduUpdate_Txt2Date_Text <> "" Then 
						zGetWWW_BaiduUpdate_Txt2Date = trim(zGetWWW_BaiduUpdate_Txt2Date_Text)
					End If
					If InStr(zGetWWW_BaiduUpdate_Txt2Date," ") > 0 Then 
						zGetWWW_BaiduUpdate_Txt2Date = Mid(zGetWWW_BaiduUpdate_Txt2Date, InStr(zGetWWW_BaiduUpdate_Txt2Date," ")+1, Len(zGetWWW_BaiduUpdate_Txt2Date))
					End If
					If InStr(zGetWWW_BaiduUpdate_Txt2Date," ") > 0 Then 
						zGetWWW_BaiduUpdate_Txt2Date = Mid(zGetWWW_BaiduUpdate_Txt2Date, InStr(zGetWWW_BaiduUpdate_Txt2Date," ")+1, Len(zGetWWW_BaiduUpdate_Txt2Date))
					End If
				End If
			End If
			If InStr(zGetWWW_BaiduUpdate_Txt2Date," ") > 0 Then 
				zGetWWW_BaiduUpdate_Txt2Date = Mid(zGetWWW_BaiduUpdate_Txt2Date, InStr(zGetWWW_BaiduUpdate_Txt2Date," ")+1, Len(zGetWWW_BaiduUpdate_Txt2Date))
			End If
		End If
	End function
	
	Public Function zGetWWW_Baidu_Pages(zGetWWW_Baidu_Pages_Ori)
		zGetWWW_Baidu_Pages = BaiDuSearchLeftStr & SearchSiteLeftStr & Replace(zGetWWW_Baidu_Pages_Ori,"www.","")
	End Function
	
	Public Function zGetWWW_Baidu_Pages_Ct(zGetWWW_Baidu_Pages_Ct_Text)
		zGetWWW_Baidu_Pages_Ct = 0
		zTmp1 = "class=""site_tip""><strong>"
		If InStr(zGetWWW_Baidu_Pages_Ct_Text,zTmp1) > 0 Then
			zGetWWW_Baidu_Pages_Ct_Text = Mid(zGetWWW_Baidu_Pages_Ct_Text, InStr(zGetWWW_Baidu_Pages_Ct_Text,zTmp1)+Len(zTmp1), Len(zGetWWW_Baidu_Pages_Ct_Text))
			If InStr(zGetWWW_Baidu_Pages_Ct_Text,"</strong>") > 0 Then
				zGetWWW_Baidu_Pages_Ct_Text = Mid(zGetWWW_Baidu_Pages_Ct_Text, 1, InStr(zGetWWW_Baidu_Pages_Ct_Text,"</strong>")-1)
				zGetWWW_Baidu_Pages_Ct = zGetWWW_Baidu_Pages_Ct_Text
				If zGetWWW_Baidu_Pages_Ct <> "" Then
					zGetWWW_Baidu_Pages_Ct = Replace(zGetWWW_Baidu_Pages_Ct,",","")
					zGetWWW_Baidu_Pages_Ct = Mid(zGetWWW_Baidu_Pages_Ct, 8, 100)
					zGetWWW_Baidu_Pages_Ct = Mid(zGetWWW_Baidu_Pages_Ct, 1, Len(zGetWWW_Baidu_Pages_Ct)-2)
				End If
			End If
		End If
	End function

	Public Function zGetWWW_Key_Url_Old(zGetWWW_Key_Url_Ori)
		zGetWWW_Key_Url_Old = SearchTopLeftStr & zGetWWW_Key_Url_Ori
	End Function
	
	Public Function zGetWWW_Key_Url(zGetWWW_Key_Url_Ori,zGetWWW_Key_Url_Num)
		If CDbl(zGetWWW_Key_Url_Num)<>0 Then
			zGetWWW_Key_Url = SearchTopLeftStr & SearchTopRnStr & "=" & zGetWWW_Key_Url_Num & "&" & SearchTopQ1Str & "=" & zGetWWW_Key_Url_Ori
		Else
			zGetWWW_Key_Url = SearchTopLeftStr & SearchTopQ1Str & "=" & zGetWWW_Key_Url_Ori
		End If
	End Function

	Public Function zGetWWW_Keyword_URLS(zGetWWW_Keyword_URLS_Text,zGetWWW_Keyword_URLS_Mode)
		Dim zGetWWW_Keyword_URLS_Tmp
		zGetWWW_Keyword_URLS=""
		If InStr(zGetWWW_Keyword_URLS_Text,"<div class=""nors"">")>0 Then 
			Exit Function
		End If
		While InStr(zGetWWW_Keyword_URLS_Text,"class=""result")>0
			zGetWWW_Keyword_URLS_Text = Mid(zGetWWW_Keyword_URLS_Text, InStr(zGetWWW_Keyword_URLS_Text, "class=""result"),Len(zGetWWW_Keyword_URLS_Text))
			If Left(zGetWWW_Keyword_URLS_Text,Len("class=""result-op")) = "class=""result-op" Then
				zGetWWW_Keyword_URLS_Tmp = "zIsGuanGao.baidu.com"
				If zGetWWW_Keyword_URLS<>"" Then 
					zGetWWW_Keyword_URLS = zGetWWW_Keyword_URLS & "|||" & Trim(zGetWWW_Keyword_URLS_Tmp)
				Else
					zGetWWW_Keyword_URLS = Trim(zGetWWW_Keyword_URLS_Tmp)
				End If
			Else
				zGetWWW_Keyword_URLS_Tmp = Mid(zGetWWW_Keyword_URLS_Text, 1, InStr(zGetWWW_Keyword_URLS_Text,"</table>"))
				If InStr(zGetWWW_Keyword_URLS_Tmp," class=""g"">")>0 Then
					zGetWWW_Keyword_URLS_Tmp = Mid(zGetWWW_Keyword_URLS_Tmp, InStr(zGetWWW_Keyword_URLS_Tmp," class=""g"">")+11, Len(zGetWWW_Keyword_URLS_Tmp))
				End If
				If InStr(zGetWWW_Keyword_URLS_Tmp,"#008000")>0 Then
					zGetWWW_Keyword_URLS_Tmp = Mid(zGetWWW_Keyword_URLS_Tmp, InStr(zGetWWW_Keyword_URLS_Tmp,"#008000")+9, Len(zGetWWW_Keyword_URLS_Tmp))
				End If
				zGetWWW_Keyword_URLS_Tmp = Trim(zGetWWW_Keyword_URLS_Tmp)
				if CDbl(zGetWWW_Keyword_URLS_Mode) = zGolbal_Seo_JJ Then
					zGetWWW_Keyword_URLS_Tmp = Mid(zGetWWW_Keyword_URLS_Tmp,1,InStr(zGetWWW_Keyword_URLS_Tmp,"/")-1)
				End If
				If CDbl(zGetWWW_Keyword_URLS_Mode) = zGolbal_Seo_Price Then
					zGetWWW_Keyword_URLS_Tmp = Mid(zGetWWW_Keyword_URLS_Tmp,1,InStr(zGetWWW_Keyword_URLS_Tmp," ")-1)
				End If
				If zGetWWW_Keyword_URLS_Tmp<>"" Then
					If Left(zGetWWW_Keyword_URLS_Tmp,1)=">" Then 
						zGetWWW_Keyword_URLS_Tmp = Mid(zGetWWW_Keyword_URLS_Tmp,2,Len(zGetWWW_Keyword_URLS_Tmp))
					End If
					If zGetWWW_Keyword_URLS<>"" Then 
						zGetWWW_Keyword_URLS = zGetWWW_Keyword_URLS & "|||" & Trim(zGetWWW_Keyword_URLS_Tmp) 
					Else 
						zGetWWW_Keyword_URLS = Trim(zGetWWW_Keyword_URLS_Tmp)
					End If
				End If
			End If
			zGetWWW_Keyword_URLS_Text = mid(zGetWWW_Keyword_URLS_Text,11,len(zGetWWW_Keyword_URLS_Text))
		Wend
	End function
	
	Public Function zGetWWW_Keyword_PageS(zGetWWW_Keyword_PageS_Text)
		zGetWWW_Keyword_PageS = 0
		If InStr(zGetWWW_Keyword_PageS_Text,"找到相关结果")>0 Then
			zStr_Tmp = Mid(zGetWWW_Keyword_PageS_Text,InStr(zGetWWW_Keyword_PageS_Text,"找到相关结果")+6,Len(zGetWWW_Keyword_PageS_Text))
			zStr_Tmp = Replace(zStr_Tmp,"约","")
			zStr_Tmp = Mid(zStr_Tmp,1,InStr(zStr_Tmp,"个")-1)
			zGetWWW_Keyword_PageS = Replace(zStr_Tmp,",","")
		End If
	End Function
	
	Public Sub zTnT_Pr()
		Dim zTnT_Pr_Text
		zTnT_Pr_URL = zGetWWW_PRUrl(SeoClassInfo_Ori_Url)
		Response.Write "<a href='" & zTnT_Pr_URL & "' target='_blank'>" & zTnT_Pr_URL &"</a><br />"
		HttpObj.Async = False
		HttpObj.CharSet = "UTF-8"
		HttpObj.Method = "GET"
		HttpObj.Url = zTnT_Pr_URL
		zTnT_Pr_Text = HttpObj.Open
		SeoClassInfo_Pr = 0
		If zTnT_Pr_Text<>"" Then
			SeoClassInfo_Pr = zGetWWW_PRUrl_Txt2Pr(zTnT_Pr_Text)
		End If
	End Sub
	
	Public Sub zTnT_Baidu_UpdateDate()
		Dim zTnT_Baidu_UpdateDate_text
		zTnT_Baidu_UpdateDate_Url = zGetWWW_BaiduUpdate(SeoClassInfo_Ori_Url)
		HttpObj.Async = False
		HttpObj.CharSet = "UTF-8"
		HttpObj.Method = "GET"
		HttpObj.Url = zTnT_Baidu_UpdateDate_Url
		zTnT_Baidu_UpdateDate_text = HttpObj.Open
		SeoClassInfo_Baidu_UpdateDate = ""
		If zTnT_Baidu_UpdateDate_text<>"" Then
			SeoClassInfo_Baidu_UpdateDate = zGetWWW_BaiduUpdate_Txt2Date(zTnT_Baidu_UpdateDate_text)
		End If
	End Sub
  
	Public Sub zTnT_Baidu_Pages()
		Dim zTnT_Baidu_Pages_Text
		zTnT_Baidu_Pages_URL = zGetWWW_Baidu_Pages(SeoClassInfo_Ori_Url)
		HttpObj.Async = False
		HttpObj.CharSet = "UTF-8"
		HttpObj.Method = "GET"
		HttpObj.Url = zTnT_Baidu_Pages_URL
		zTnT_Baidu_Pages_Text = HttpObj.Open
		SeoClassInfo_Baidu_Pages = 0
		If zTnT_Baidu_Pages_Text<>"" Then
			SeoClassInfo_Baidu_Pages =zGetWWW_Baidu_Pages_Ct(zTnT_Baidu_Pages_Text)
		End If
	End Sub
	
	Public Sub zTnt_FindKeyword()
		Dim zTnT_Baidu_Keyword_text
		If Baidu_Mode = zGolbal_Seo_JJ Then
			Baidu_Key_Url = zGetWWW_Key_Url(Baidu_Keyword_Str,50)
		Else
			Baidu_Key_Url = zGetWWW_Key_Url(Baidu_Keyword_Str,0)
		End If
		HttpObj.Async = False
		HttpObj.CharSet = "UTF-8"
		HttpObj.Method = "GET"
		HttpObj.Url = Baidu_Key_Url
		zTnT_Baidu_Keyword_text = HttpObj.Open
		Baidu_Keyword_Urls = ""
		If zTnT_Baidu_Keyword_text<>"" Then
			Baidu_Keyword_Urls = zGetWWW_Keyword_URLS(zTnT_Baidu_Keyword_text,Baidu_Mode)
			If Baidu_Mode=16 Then 
				Baidu_Keyword_PageS = zGetWWW_Keyword_PageS(zTnT_Baidu_Keyword_text)
			End If
		End If
	End Sub
	
	Public Function zTest_UrlIsGood(zTest_UrlIsGood_Url)
		zTest_UrlIsGood = false
		zTest_UrlIsGood_Url = LCase(zTest_UrlIsGood_Url)
		If Left(zTest_UrlIsGood_Url,7)="http://" Then 
			zTest_UrlIsGood_Url = Mid(zTest_UrlIsGood_Url,8,Len(zTest_UrlIsGood_Url))
		End If
		If InStr(LCase(zTest_UrlIsGood_Url),".baidu.com")>0 Then 
			zTest_UrlIsGood = true
			Exit Function
		End if
		zTest_PathS = Split(zTest_UrlIsGood_Url,"/")
		If UBound(zTest_PathS)>1 Then 
			Exit Function
		End If
		If UBound(zTest_PathS)=1 Then 
			If zTest_PathS(1)<>"" Then 
				Exit Function
			End If
		End If
		zTest_PathSS = Split(zTest_PathS(0),".")
		If (UBound(zTest_PathSS)=1) Or (UBound(zTest_PathSS)=2 And LCase(zTest_PathSS(0))="www") Then
			zTest_UrlIsGood = true
		End If
	End Function
	
	Public Function zGetSeoPrice_Ex_Num(zGetSeoPrice_Ex_URL)
		zGetSeoPrice_Ex_Num = 0
		zGetSeoPrice_Ex_URLS = Split(zGetSeoPrice_Ex_URL,"|||")
		For zGetSeoPrice_Ex_I=0 To UBound(zGetSeoPrice_Ex_URLS)
			If zTest_UrlIsGood(zGetSeoPrice_Ex_URLS(zGetSeoPrice_Ex_I)) Then 
				zGetSeoPrice_Ex_Num = zGetSeoPrice_Ex_Num + 1
			End If
		Next
	End function
	
End Class
%>